/* Janus Chat - Version 1.0
 * Authors: Matthew Perry
 *          Michael Freid
 *          Marc Latou
 *          Richard Lee
 *
 * The Janus Chat Client is a highly secured
 * peer-to-peer chat client designed to facilitate
 * the transfer of sensitive data or as a communication
 * medium for the extra paranoid
 *
 * This file contains the implementation for the AcceptDialog
 * QT class which describes the window that appears on
 * new connections */

#include "acceptdialog.h"
#include "ui_acceptdialog.h"
#include <QHostAddress>

/* The accept dialog constructor:
 * This constructor is relatively simple
 * it takes a socket and constructs itself
 * to display the socket's peer address */
AcceptDialog::AcceptDialog(QTcpSocket* sock, QWidget *parent) :
    QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint),
    ui(new Ui::AcceptDialog)
{
    //Initialize this class' UI Elements (Widgets)
    ui->setupUi(this);

    //Display the peer's IP
    mySock = sock;
    ui->labelIP->setText( ui->labelIP->text() + sock->peerAddress().toString() );
}

/* Destructor */
AcceptDialog::~AcceptDialog()
{
    delete ui;
}

/* The Ignore Button slot:
 * This slot is activated when the
 * ignore button is clicked. It disconnects from
 * the socket and closes the dialog */
void AcceptDialog::on_buttonIgnore_clicked()
{
    //Close the socket and the dialog if the ignore button is pressed
    mySock->disconnectFromHost();
    this->close();
}

/* The Accept Button slot:
 * This slot is activated when the accept
 * button is clicked. It emits a signal which
 * notifies the MainWindow that this socket was
 * accepted. */
void AcceptDialog::on_buttonAccept_clicked()
{
    //Emit a signal telling the main window to spawn a new chattab
    emit accepted( mySock );
    this->close();
}
